// FormAddin.h : Declaration of the CFormAddin
#pragma once
#include "resource.h"       // main symbols



#include "OutlookAddin_i.h"
#include "SettingForm.h"
#include "SendForm.h"
#include "SyncSetting.h"
#include "Reminder.h"
#include "ContactSyncTask.h"
#include "ReminderSyncTask.h"

#if defined(_WIN32_WCE) && !defined(_CE_DCOM) && !defined(_CE_ALLOW_SINGLE_THREADED_OBJECTS_IN_MTA)
#error "Single-threaded COM objects are not properly supported on Windows CE platform, such as the Windows Mobile platforms that do not include full DCOM support. Define _CE_ALLOW_SINGLE_THREADED_OBJECTS_IN_MTA to force ATL to support creating single-thread COM object's and allow use of it's single-threaded COM object implementations. The threading model in your rgs file was set to 'Free' as that is the only threading model supported in non DCOM Windows CE platforms."
#endif

using namespace ATL;
using namespace Office;

extern _ATL_FUNC_INFO OnClickSettingButtonInfo;
extern _ATL_FUNC_INFO OnClickSendButtonInfo;
extern _ATL_FUNC_INFO OnClickSyncButtonInfo;
extern _ATL_FUNC_INFO OnClickSyncSettingButtonInfo;
//extern _ATL_FUNC_INFO OnReminderAddInfo;
//extern _ATL_FUNC_INFO OnReminderChangeInfo;
//extern _ATL_FUNC_INFO OnReminderRemoveInfo;
//typedef IDispatchImpl<IRibbonCallback, &__uuidof(IRibbonCallback)> CallbackImpl;

// CFormAddin

class ATL_NO_VTABLE CFormAddin :
	public CComObjectRootEx<CComSingleThreadModel>,
	public CComCoClass<CFormAddin, &CLSID_FormAddin>,
	public IDispatchImpl<IFormAddin, &IID_IFormAddin, &LIBID_OutlookAddinLib, /*wMajor =*/ 1, /*wMinor =*/ 0>,
	public IDispatchImpl<_IDTExtensibility2, &__uuidof(_IDTExtensibility2), &LIBID_AddInDesignerObjects, /* wMajor = */ 1>,
	public IDispEventSimpleImpl<1,CFormAddin,&__uuidof(Office::_CommandBarButtonEvents)>,
	public IDispEventSimpleImpl<2,CFormAddin,&__uuidof(Office::_CommandBarButtonEvents)>,
	public IDispEventSimpleImpl<3,CFormAddin,&__uuidof(Office::_CommandBarButtonEvents)>,
	public IDispEventSimpleImpl<4,CFormAddin,&__uuidof(Office::_CommandBarButtonEvents)>
	//public IDispatchImpl<IRibbonExtensibility, &__uuidof(IRibbonExtensibility), &__uuidof(__Office), /* wMajor = */ 2, /* wMinor = */ 5>,
	//public CallbackImpl
	//public IDispEventSimpleImpl<5,CFormAddin,&__uuidof(Outlook::ReminderCollectionEvents)>
{
public:
	Outlook::_ApplicationPtr spAppCache;
	CFormAddin()
	{
		spSettingForm = NULL;
		spSendForm = NULL;
		spSyncSettingForm = NULL;
		regesiter = NULL;
		ctask = NULL;
		rtask = NULL;
	}

	DECLARE_REGISTRY_RESOURCEID(IDR_FORMADDIN)


	BEGIN_COM_MAP(CFormAddin)
		COM_INTERFACE_ENTRY(IFormAddin)
		COM_INTERFACE_ENTRY2(IDispatch, _IDTExtensibility2)
		COM_INTERFACE_ENTRY(_IDTExtensibility2)
		//COM_INTERFACE_ENTRY(IRibbonExtensibility)
		//COM_INTERFACE_ENTRY(IRibbonCallback)
	END_COM_MAP()

	BEGIN_SINK_MAP(CFormAddin)
		SINK_ENTRY_INFO(1, __uuidof(Office::_CommandBarButtonEvents),/*dispid*/ 0x01, OnClickSettingButton, &OnClickSettingButtonInfo)
		SINK_ENTRY_INFO(2, __uuidof(Office::_CommandBarButtonEvents),/*dispid*/ 0x01, OnClickSendButton, &OnClickSendButtonInfo)
		SINK_ENTRY_INFO(3, __uuidof(Office::_CommandBarButtonEvents),/*dispid*/ 0x01, OnClickSyncButton, &OnClickSyncButtonInfo)
		SINK_ENTRY_INFO(4, __uuidof(Office::_CommandBarButtonEvents),/*dispid*/ 0x01, OnClickSyncSettingButton, &OnClickSyncSettingButtonInfo)
		//SINK_ENTRY_INFO(5, __uuidof(Outlook::ReminderCollectionEvents),/*dispid*/ 0xFA94, OnReminderAdd, &OnReminderAddInfo)
		//SINK_ENTRY_INFO(5, __uuidof(Outlook::ReminderCollectionEvents),/*dispid*/ 0xFA95, OnReminderChange, &OnReminderChangeInfo)
		//SINK_ENTRY_INFO(5, __uuidof(Outlook::ReminderCollectionEvents),/*dispid*/ 0xFA97, OnReminderRemove, &OnReminderRemoveInfo)
		//SINK_ENTRY_INFO(2,__uuidof(Outlook::ApplicationEvents),/*dispid*/0xf005,OnOptionsAddPages,&OnOptionsAddPagesInfo)
	END_SINK_MAP()

	DECLARE_PROTECT_FINAL_CONSTRUCT()

	HRESULT FinalConstruct()
	{
		return S_OK;
	}

	void FinalRelease()
	{
		delete spSettingForm;
		delete spSendForm;
		delete spSyncSettingForm;
		delete regesiter;
		delete ctask;
		delete rtask;
	}

public:

	void __stdcall OnClickSettingButton(IDispatch* Ctrl, VARIANT_BOOL* CancelDefault);
	void __stdcall OnClickSendButton(IDispatch* Ctrl, VARIANT_BOOL* CancelDefault);
	void __stdcall OnClickSyncButton(IDispatch* Ctrl, VARIANT_BOOL* CancelDefault);
	void __stdcall OnClickSyncSettingButton(IDispatch* Ctrl, VARIANT_BOOL* CancelDefault);
	//void __stdcall OnReminderAdd(Outlook::_Reminder* ReminderObject);
	//void __stdcall OnReminderChange(Outlook::_Reminder* ReminderObject);
	//void __stdcall OnReminderRemove();

	// _IDTExtensibility2 Methods
public:
	STDMETHOD(OnConnection)(LPDISPATCH Application, ext_ConnectMode ConnectMode, LPDISPATCH AddInInst, SAFEARRAY * * custom);
	STDMETHOD(OnDisconnection)(ext_DisconnectMode RemoveMode, SAFEARRAY * * custom);
	STDMETHOD(OnAddInsUpdate)(SAFEARRAY * * custom);
	STDMETHOD(OnStartupComplete)(SAFEARRAY * * custom);
	STDMETHOD(OnBeginShutdown)(SAFEARRAY * * custom);



private:
	Office::_CommandBarButtonPtr spButtonSetting;
	Office::_CommandBarButtonPtr spButtonSend;
	Office::_CommandBarButtonPtr spButtonSync;
	Office::_CommandBarButtonPtr spButtonSyncSetting;
	CSettingForm* spSettingForm;
	CSendForm* spSendForm;
	CSyncSetting* spSyncSettingForm;
	Regesiter* regesiter;
	ContactSyncTask* ctask;
	ReminderSyncTask* rtask;
};

OBJECT_ENTRY_AUTO(__uuidof(FormAddin), CFormAddin)